package ufrj.safcp.controller;

import ufrj.safcp.view.SAFCPFrame;

public abstract class BaseController {
	
	public abstract State[] getAllStates();
	
	protected SAFCPFrame mainFrame;
	
	protected State currentState;
	
	public State getCurrentState() {
		return currentState;
	}
	
	protected void setCurrentState(State s) {
		this.currentState = s;
	}
	
	public void start() {
		mainFrame.setVisible(true);
	}
	
	public void changeState(State from, State to) {
		if (from != null) {
			from.exitState();
		}
		
		setCurrentState(to);

		new Thread(new Runnable() {
			public void run() {
				mainFrame.refresh();
			}
		}).start();
		
		// after refresh to can access visual components
		to.enterState();
	}
	
}
